﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using JsonTest1.Data;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace JsonTest1.Json
{
    public class TrackBuilder : JSONBuilder<Track>
    {
        public override Track Build(JObject jsonObject)
        {
            Track data = new Track();
            data.Id = (int)jsonObject["id"];
            data.Duration = (int)jsonObject["duration"];
            data.Name = (string)jsonObject["name"];
            data.Stream = (string)jsonObject["stream"];
            try
            {
                data.Rating=(double)jsonObject["rating"];
            }
            catch (JsonException e)
            {
                data.Rating = -1;
            }
            data.Url = (string)jsonObject["url"];
            try
            {
                data.Numalbum = (int)jsonObject["numalbum"];
            }
            catch (JsonException e)
            {
                data.Numalbum = 0;
            }
            return data;
        }
    }
}
